package com.multicampus.minishop.view.user;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.multicampus.minishop.framework.Action;
import com.multicampus.minishop.services.user.UserService;
import com.multicampus.minishop.services.user.impl.UserServiceImpl;
import com.multicampus.minishop.user.vo.UserVO;

public class DeleteUserAction extends Action {

	@Override
	public String execute(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		
		UserService service = new UserServiceImpl();
		String userId = request.getParameter("userId");
		
		HttpSession session = request.getSession();
		UserVO user = ( UserVO )session.getAttribute("user");
		
		if(userId != null && userId.equals(user.getUserId())) {
			service.deleteUser(userId);
			session.invalidate();
		}
		
		return "redirect:/index.jsp";
	}

}
